home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15502 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  48 lines

  1. Path: news.eecs.umich.edu!usenet
  2. From: niranjan@eecs.umich.edu (Niranjan Ramakrishnan)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: simulating fscanf for strings?
  5. Date: 19 Apr 1996 09:26:01 -0400
  6. Organization: Department of EECS, University of Michigan, Ann Arbor
  7. Sender: niranjan@wits-end.eecs.umich.edu
  8. Message-ID: <iefd9545ora.fsf@wits-end.eecs.umich.edu>
  9. References: <ief20llwf6c.fsf@wits-end.eecs.umich.edu>
  10. NNTP-Posting-Host: wits-end.eecs.umich.edu
  11. In-reply-to: niranjan@eecs.umich.edu's message of 18 Apr 1996 14:38:35 -0400
  12. X-Newsreader: Gnus v5.1
  13.  
  14. >>>>> "Niranjan" == Niranjan Ramakrishnan <niranjan@eecs.umich.edu> writes:
  15.  
  16.     Niranjan> Hi,
  17.     Niranjan> Does  anyone know of  a method  to simulate  what fscanf
  18. does (in the case of
  19.     Niranjan> a file pointer) in a character pointer? The only closest
  20. thing available is
  21.     Niranjan> sscanf but it  doesn't automatically advance the pointer
  22.  
  23. Hi again,
  24.  
  25. I got quite a few responses for my question and I'd like to thank everybody.
  26. Just thought I'd mention that I think the solution to this (garnered from the
  27. replies) is using the "%n" option.
  28.  
  29. eg
  30.  
  31. char *s=(char *)malloc(sizeof(char)*20),t[10];
  32. int j=6,k=7,i,l,c;
  33. sprintf(s,"%d %d Hello",j,k);
  34. sscanf(s,"%d %d %n",&i,&l,&c); /* c contains number of bytes read so far */
  35. s+=c;
  36. sscanf(s,"%s",t);
  37. printf("i is %d, l is %d %s",i,l,t);
  38.  
  39. --- prints :  i is 6, l is 7 Hello ---
  40.  
  41. Thanks once again,
  42.  
  43. Niranjan
  44.  
  45. -- 
  46. - Niranjan
  47.  
  48.